package com.example.tvmatchddemo.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;

import androidx.viewpager.widget.ViewPager;

/**
 * created by liangkun on ${DATA}
 * Describe:
 */

public class NoScrollViewPager extends ViewPager {
    private boolean isCanScroll = true;

    public NoScrollViewPager(Context context) {
        super(context);
    }

    public NoScrollViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    /**
     * 设置其是否能滑动换页
     *
     * @param isCanScroll false 不能换页， true 可以滑动换页
     */
    public void setScanScroll(boolean isCanScroll) {
        this.isCanScroll = isCanScroll;
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        return isCanScroll ;
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        return isCanScroll ;

    }


    @Override
    protected boolean dispatchGenericFocusedEvent(MotionEvent event) {
//        return super.dispatchGenericFocusedEvent(event);
        return isCanScroll;
    }
}
